#include "state_endgame.h"
#include "game.h"
#include "queue.h"
#include "player.h"
#include <stdio.h>

void State_EndGame::init(Game * g){
	GameState::init(g);
	Player * p;
	for(int i = 0; i < g->getPlayerCount(); ++i)
	{
		p = g->getPlayer(i);
		stats.enqueue(EndGameStats(p, p->getCash(), p->getValueOfAllStock()));
	}
	stats.sort();
	stats.reverse();
}

void State_EndGame::draw(Graphics * g)
{
	g->fillRect(5, 5, 40, 15, '#', Graphics::DARK_GRAY);
	g->fillRect(6, 8, 38, 10, ' ', Graphics::DARK_GRAY);
	sprintf_s(g->TEXT, g->TEXT_SIZE, this->reasonTheGameEnded, detail);
	char line[30];
	g->drawText(g->TEXT, 7, 6, m_game->flashColor(3));
	for(int i = 0; i < stats.size; ++i)
	{
		sprintf_s(line, sizeof(line), "$%10d %s", stats.list[i].worth, stats.list[i].p->getName());
		g->drawText(line, 10, 9+i);
	}
	sprintf_s(line, sizeof(line), "(escape to quit)");
	g->drawText(line, 10, 19, m_game->flashColor(4));
}

void State_EndGame::processInput(int key)
{
}
